#!/bin/bash

timeout=8
set_timer() { (
  sleep $timeout
  pid_exists=`ps -e | grep $$`
  if [ -n "$pid_exists" ]
  then
    echo "Runtime exceeded "$timeout" seconds !!" 
    kill $$
  fi
)& }

set_timer

for i in {0..4}
do
  echo "going... "$i
  sleep 1
done

# trap "echo Booh!" SIGINT SIGTERM
# echo "pid is $$"
# 
# while :			# This is the same as "while true".
# do
#         sleep 60	# This script is not really doing anything.
# done
# 
# 
# kill -USR1 $$	
# exit 0